#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int takeAttendance(vector<int>& records) {


        int left = 0;
        int right = records.size() - 1;

        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (records[mid] != mid)
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }

        if (records[right] == right) return right + 1;
        return right;
    }
};